<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" session="false"%>
<%@ include file="/WEB-INF/view/common/loginCheck.jspf" %>
<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<link rel="stylesheet" type="text/css" href="${ROOT}/static/js/easyui/themes/default/easyui.css" />
	<link rel="stylesheet" type="text/css" href="${ROOT}/static/js/easyui/themes/icon.css" />
</head>	

<body>	
<div class="easyui-layout" data-options="fit:true">
    <div data-options="region:'center',title:'系统属性列表'" style="padding:5px">
    	<table id="sysPropDataList" style="width:99%;height:100%"></table>
		<div id="sysPropToolbar">
			<div style="padding:3px;">
				状态：<select class="easyui-combobox" id="stateSelectBox">
				 	<option value="">--选择状态--</option>
				 	<option value="1">启用</option>
                	<option value="0">草稿</option>
                	<option value="-1">停用</option>
                	<option value="-2">删除</option>
				</select>
				<input class="easyui-searchbox" id="sysPropSearchBox" data-options="prompt:'名称', searcher:searchSysProp" style="width:30%" />
			</div>
			<div>
				<t:permission codes="SYSPROP-VIEW,SYSPROP-MODIFY">
			    <a href="javascript:void(0)" title="添加系统属性" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="showSysPropEditDlg(false)">新增</a>
			    <a href="javascript:void(0)" title="编辑系统属性" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="showSysPropEditDlg(true)">编辑</a>
			    </t:permission>
			    <t:permission codes="SYSPROP-STATE">
			    <select class="easyui-combobox" id="stateChangeBox">
				 	<option value="">--修改状态--</option>
				 	<option value="1">启用</option>
                	<option value="0">草稿</option>
                	<option value="-1">停用</option>
                	<option value="-2">删除</option>
				</select>
				</t:permission>
				<t:permission codes="SYSPROP-DEL">
			    <a href="javascript:void(0)" title="彻底删除系统属性" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="delSysProp()">彻底删除</a>
			    </t:permission>
		    </div>
		</div>
		
		<div id="sysPropEditDlg"></div>
    </div>
</div>

<script type="text/javascript" src="${ROOT}/static/js/jquery/jquery.min.js"></script>
<script type="text/javascript" src="${ROOT}/static/js/easyui/jquery.easyui.min.js"></script>
<script type="text/javascript" src="${ROOT}/static/js/easyui/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" src="${ROOT}/static/js/common/common.js"></script>
<script type="text/javascript">
	var state = null;
	var stateChange = null;
	$(function () {
		$('#sysPropDataList').datagrid({
		    url:'${ROOT}/sysprop/list?_rt=' + new Date().getTime(),
		    columns:[[
				{field: 'id', width: '10%', checkbox: true, align: 'left'},
		        {field: 'propKey', title: '键', width: '200', align: 'left'},
		        {field: 'propValue', title: '值', width: '200', align: 'left'},
		        {field: 'remark', title: '备注', width: '200', align: 'left'},
		        {field: 'orderValue', title: '排序值', width: '200', align: 'left'},
		        {field: 'state', title: '状态', width: '50', align: 'center',
		        	formatter:function(value, row, index) {
		        		var color = 'green';
		        		var name = '启用';
		        		var style = '';
		        		if (value == 0) {
		        			color = 'gray';
		        			name = '草稿';
		        		} else if (value == -1 || value == -2) {
		        			color = 'red';
		        			name = value == -1 ? '停用' : '删除';
		        			if (value == -2) {
		        				style = 'text-decoration:line-through;';
		        			}
		        		}
			        	return '<font color="' + color + '"><b style="' + style + '">' + name + '</b></font>';		        			
		            }
		        },
		        {field: 'createdTime', title: '创建时间', width: '130', align: 'left'},
		        {field: 'updatedTime', title: '更新时间', width: '130', align: 'left'}
		    ]],
		    idField: 'id',
		    toolbar: '#sysPropToolbar',
	    	rownumbers: true,
	    	pagination: true,
	    	pageSize: 20,
	    	singleSelect: false,
	    	checkOnSelect: true,
	    	scrollbarSize: 12,
	    	onDblClickRow: function (index, row) {
	    		<t:permission codes="SYSPROP-VIEW,SYSPROP-MODIFY">
	    		var url = '${ROOT}/sysprop/edit?id=' + row.id + '&_rt=' + new Date().getTime();
	    		$('#sysPropEditDlg').dialog({
	    		    title: '修改系统属性',
	    		    width: 400,
	    		    height: 300,
	    		    closed: false,
	    		    cache: false,
	    		    href: url,
	    		    modal: true
	    		});
	    		$('#sysPropDataList').datagrid('clearSelections');
	        	$('#sysPropDataList').datagrid('clearChecked');
	        	$('#sysPropDataList').datagrid('selectRow', index);
	        	</t:permission>
	    	}
		});
		
		$('#stateSelectBox').combobox({
		    onSelect: function (node) {
		    	state = node.value;
		    	searchSysProp();
		    }
		});
		$('#stateChangeBox').combobox({
		    onSelect: function (node) {
		    	stateChange = node.value;
		    	if ($.trim(stateChange) != '') {
		    		stateSysProp();
		    	}
		    }
		});
	});
	
	function searchSysProp() {
		$('#sysPropDataList').datagrid('load', {
		    keyword: $.trim($('#sysPropSearchBox').searchbox('getValue')),
		    state: state
		});
		$('#sysPropDataList').datagrid('clearSelections');
    	$('#sysPropDataList').datagrid('clearChecked');
	}
	
	function showSysPropEditDlg(isEdit) {
		var selectedRows = $('#sysPropDataList').datagrid('getSelections');
		if (isEdit) {
			if (selectedRows == null ||selectedRows.length <= 0) {
				APP.warning('请选择一个要修改的系统属性');
				return;
			}
			if (selectedRows.length != 1) {
				APP.warning('一次只能修改一个系统属性哦');
				return;
			}
		}
		var url = '${ROOT}/sysprop/edit?id=' + (isEdit ? selectedRows[0].id : '') + '&_rt=' + new Date().getTime();
		$('#sysPropEditDlg').dialog({
		    title: (isEdit ? '修改系统属性' : '新增系统属性'),
		    width: 400,
		    height: 300,
		    closed: false,
		    cache: false,
		    href: url,
		    modal: true
		});
	}
	
	function delSysProp() {
		var selectedRows = $('#sysPropDataList').datagrid('getSelections');
		if (selectedRows == null ||selectedRows.length <= 0) {
			APP.warning('请选择要删除的系统属性');
			return;
		}
		var msg = '你确定要删除选中的系统属性吗?';
		APP.confirm(msg, function (flag) {
			if (flag) {
				var ids = '';
				for (var i = 0; i < selectedRows.length; i++) {
					if (i > 0) {
						ids += ',';
					}
					ids += selectedRows[i].id;
				}
				APP.post({
					url: '${ROOT}/sysprop/del?_rt=' + new Date().getTime(),
					data: {
						ids: ids
					},
					success: function (data) {
						var success = data.success;
						var msg = data.msg;
						if (success == undefined) {
							var json = eval('(' + data + ')');
							success = json.success;
							msg = json.msg;
						}
						if (success) {
							$('#sysPropDataList').datagrid('reload');
							APP.message('删除成功');
							$('#sysPropDataList').datagrid('clearSelections');
				        	$('#sysPropDataList').datagrid('clearChecked');
						} else {
							APP.error(msg);
						}
					}
				});
			}
		});
	}
	
	function stateSysProp() {
		var selectedRows = $('#sysPropDataList').datagrid('getSelections');
		if (selectedRows == null ||selectedRows.length <= 0) {
			APP.warning('请选择要修改状态的系统属性');
			$('#stateChangeBox').combobox("setValue", '');
			return;
		}
		var msg = '你确定要修改选中的系统属性吗?';
		APP.confirm(msg, function (flag) {
			if (flag) {
				var ids = '';
				for (var i = 0; i < selectedRows.length; i++) {
					if (i > 0) {
						ids += ',';
					}
					ids += selectedRows[i].id;
				}
				APP.post({
					url: '${ROOT}/sysprop/state?_rt=' + new Date().getTime(),
					data: {
						ids: ids,
						state: stateChange
					},
					success: function (data) {
						var success = data.success;
						var msg = data.msg;
						if (success == undefined) {
							var json = eval('(' + data + ')');
							success = json.success;
							msg = json.msg;
						}
						if (success) {
							$('#sysPropDataList').datagrid('reload');
							APP.message('修改成功');
							$('#sysPropDataList').datagrid('clearSelections');
				        	$('#sysPropDataList').datagrid('clearChecked');
				        	$('#stateChangeBox').combobox("setValue", '');
						} else {
							APP.error(msg);
						}
					}
				});
			}
		});
	}
</script>
</body>
</html>